package com.example.yifei.ui.page.common

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import coil.annotation.ExperimentalCoilApi
import com.example.yifei.data.bean.WebData
import com.example.yifei.ui.page.login.LoginPage
import com.example.yifei.ui.page.main.demand.DemandPage
import com.example.yifei.ui.page.main.home.HomePage
import com.example.yifei.ui.page.main.me.MePage
import com.example.yifei.ui.page.main.purchase.PurchasedPage
import com.example.yifei.ui.page.main.purchase.tab.PurchaseDetails
import com.example.yifei.ui.page.main.workOrder.ConfirmedPage
import com.example.yifei.ui.page.webview.WebViewPage
import com.example.yifei.utils.fromJson
import com.google.accompanist.pager.ExperimentalPagerApi

/**
 * @Author: zhudaihao
 * @Date: 2022/5/12
 * @Describe: 路由管理
 */

@ExperimentalCoilApi
@ExperimentalMaterialApi
@ExperimentalPagerApi
@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun RouteManger(navCtrl: NavHostController): @Composable (PaddingValues) -> Unit =
    {

        NavHost(
            modifier = Modifier.background(MaterialTheme.colors.background),
            navController = navCtrl,
            startDestination = RouteName.HOME
        ) {
            //首页
            composable(route = RouteName.HOME) {
                HomePage(navCtrl)
            }

            //需求
            composable(route = RouteName.PRODUCTION_DEMAND) {
                DemandPage(navCtrl)
            }

            //工单
            composable(route = RouteName.PRODUCTION_WORK_ORDER) {
                ConfirmedPage(navCtrl)
            }

            //采购
            composable(route = RouteName.PURCHASE_LIST) {
                PurchasedPage(navCtrl)
            }

            //我的
            composable(route = RouteName.PROFILE) {
                MePage(navCtrl)
            }

            //登录
            composable(route = RouteName.LOGIN) {
                LoginPage(navCtrl)
            }

            //采购列表详情
            composable(route = RouteName.PURCHASE_DETAILS) {
                PurchaseDetails(navCtrl)
            }

            //WebView
            composable(
                route = RouteName.WEB_VIEW + "/{webData}",
                arguments = listOf(navArgument("webData") { type = NavType.StringType })
            ) {
                val args = it.arguments?.getString("webData")?.fromJson<WebData>()
                if (args != null) {
                    WebViewPage(webData = args, navCtrl = navCtrl)
                }
            }


            //文章搜索页
            composable(
                route = RouteName.ARTICLE_SEARCH + "/{id}",
                arguments = listOf(navArgument("id") { type = NavType.IntType })
            ) {

            }
        }
    }